package se.sll.itintegration.catalogue.gui.service.view.users;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.cdi.CdiCamelContext;
import se.sll.itintegration.catalogue.gui.camel.cdi.CamelRoute;
import se.sll.itintegration.catalogue.gui.data.UserView;
import se.sll.itintegration.catalogue.gui.data.UsersView;
import se.sll.service.catalogue.common.exception.ResourceNotFoundException;
import se.sll.service.catalogue.common.exception.ServiceCatalogueException;
import se.sll.service.catalogue.common.exception.ValidationException;

/**
 *
 * @author Christer Palm, Nogui
 */
@Path("/view/")
@Slf4j
@Stateless
public class UsersViewService {

    @Inject
    private CdiCamelContext camelCtx;

    @GET
    @Produces("application/json; charset=UTF-8")
    @Path("/users")
    public UsersView getUsersView(@Context SecurityContext sc) throws ValidationException, ResourceNotFoundException, ServiceCatalogueException {
        log.trace("getUsersView() ENTER");
        ProducerTemplate template = camelCtx.createProducerTemplate();
        UsersView view = (UsersView) template.sendBodyAndProperty(CamelRoute.GET_USERS_VIEW, ExchangePattern.InOut, null, "sc", sc);
        log.trace("getUsersView() EXIT");
        return view;
    }

    @GET
    @Produces("application/json; charset=UTF-8")
    @Path("/user")
    public UserView getUserView(@Context SecurityContext sc) throws ValidationException, ResourceNotFoundException, ServiceCatalogueException {
        log.trace("getUserView() ENTER");
        ProducerTemplate template = camelCtx.createProducerTemplate();
        UserView view = (UserView) template.sendBodyAndProperty(CamelRoute.GET_PROFILE_VIEW, ExchangePattern.InOut, null, "sc", sc);
        log.trace("getUserView() EXIT");
        return view;
    }
}
